package com.jstyle.jclife.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;
import android.widget.ImageView;

import com.jstyle.jclife.R;
import com.jstyle.jclife.adapter.HelpAdapter;
import com.jstyle.jclife.utils.ScreenUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * FAQ
 */
public class HelpActivity extends BaseActivity {

    @BindView(R.id.bt_goal_back)
    Button btGoalBack;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.iv_share)
    ImageView ivShare;
    @BindView(R.id.el_problem)
    ExpandableListView elProblem;
    private int lastGroupPostion = -1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_problem);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        btGoalBack.setText("FAQ");
        ScreenUtils.setTitleTypeface(btGoalBack);
        ivShare.setVisibility(View.GONE);
        // TODO Auto-generated method stub
        final ExpandableListView expandableListView = (ExpandableListView)
                findViewById(R.id.el_problem);
        String[] arrayTitle = getResources().getStringArray(R.array.problrem_array);
        String[] arrayText = getResources().getStringArray(R.array.problrem_text_array);
        final HelpAdapter helpAdapter = new HelpAdapter(this, arrayTitle, arrayText);
        expandableListView.setAdapter(helpAdapter);
        expandableListView.setOnGroupExpandListener(new OnGroupExpandListener() {

            @Override
            public void onGroupExpand(int groupPosition) {
                // TODO Auto-generated method stub
                helpAdapter.setCheckItem(groupPosition);
                lastGroupPostion = groupPosition;
                for (int i = 0; i < helpAdapter.getGroupCount(); i++) {
                    if (groupPosition != i) {
                        expandableListView.collapseGroup(i);
                    }
                }
            }
        });
        expandableListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {

            @Override
            public void onGroupCollapse(int groupPosition) {
                // TODO Auto-generated method stub
                if (groupPosition == lastGroupPostion) {
                    helpAdapter.setCheckItem(-1);
                }
            }
        });

    }

    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }
}
